package class_0917skiplistextends;
import java.util.*;

public class SkipListTest {

    public static void main(String[] args) {
        SkipList<Integer, String> skipList = new SkipList<>();

        // Test insertion
        System.out.println("=== Test Insertion ===");
        skipList.insert(1, "one");
        skipList.insert(5, "five");
        skipList.insert(3, "three");
        skipList.insert(7, "seven");
        skipList.insert(2, "two");
        printSkipList(skipList);

        // Test search
        System.out.println("\n=== Test Search ===");
        System.out.println("Search 5: " + skipList.search(5));
        System.out.println("Search 10 (not found): " + skipList.search(10));

        // Test deletion
        System.out.println("\n=== Test Deletion ===");
        skipList.delete(3);
        printSkipList(skipList);

        // Test range search
        System.out.println("\n=== Test Range Search ===");
        List<String> rangeResult = skipList.rangeSearch(2, 7);
        System.out.println("Range Search (2 to 7): " + rangeResult);

        // Test range deletion
        System.out.println("\n=== Test Range Deletion ===");
        skipList.rangeDelete(2, 7);
        printSkipList(skipList);

        // Test bulk insertion
        System.out.println("\n=== Test Bulk Insertion ===");
        Map<Integer, String> bulkData = new HashMap<>();
        bulkData.put(8, "eight");
        bulkData.put(6, "six");
        bulkData.put(4, "four");
        skipList.bulkInsert(bulkData);
        printSkipList(skipList);

        // Test merge
        System.out.println("\n=== Test Merge ===");
        SkipList<Integer, String> skipList2 = new SkipList<>();
        skipList2.insert(9, "nine");
        skipList2.insert(10, "ten");
        skipList.merge(skipList2);
        printSkipList(skipList);

        // Test reBalance
        System.out.println("\n=== Test ReBalance ===");
        skipList.reBalance();
        printSkipList(skipList);
    }

    // Helper method to print SkipList content
    private static void printSkipList(SkipList<Integer, String> skipList) {
        for (SkipList.Node<Integer, String> next : skipList) {
            System.out.println("["+next.getKey() + ": " + next.getValue()+"]");
        }
    }
}
